from flask import Flask
from flask_login import LoginManager
from app.models.base import db
from flask_mail import Mail


login_manager = LoginManager()
mail = Mail()


def register_web_blueprint(app):
    from app.web import web
    app.register_blueprint(web)


# def create_app():
#     app = Flask(__name__)
#     app.config.from_object('app.secure')
#     app.config.from_object('app.setting')
#
#     register_blueprint(app)
#     db.init_app(app)
#     db.create_all(app=app)
#     return app


# def register_blueprint(app):
#     from app.web.book import web
#     app.register_blueprint(web)


def create_app(config=None):
    app = Flask(__name__)

    #: load default configuration
    app.config.from_object('app.setting')
    app.config.from_object('app.secure')


    # register_api_blueprint(app)
    register_web_blueprint(app)

    # 注册SQLAlchemy
    db.init_app(app)
    login_manager.init_app(app)
    login_manager.login_view = 'web.login'
    login_manager.login_message = '请先登录或注册'
    mail.init_app(app)



    return app
